package com.ontheroad.mysql.central.service;

import java.util.Date;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.modoumama.service.base.impl.BaseServiceImpl;

import com.ontheroad.central.model.CentralEntity;
import com.ontheroad.central.service.CentralTopicService;
import com.ontheroad.mysql.central.mapper.CentralTopicMapper;
import com.ontheroad.utils.UUIDUtil;

/*import com.ontheroad.utils.SmsUtil;*/

/**
 * Created by kedong on 2017/6/25 0021.
 */
@Service
@Transactional
public class CentralTopicServiceImpl extends BaseServiceImpl<CentralEntity, String>
		implements CentralTopicService {

	private Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private CentralTopicMapper centralTopicMapper;


	public HashMap<String, Object> insertCentral(CentralEntity centralEntity)
			throws Exception {
		HashMap<String, Object> bean  =new HashMap<String, Object>();
		log.info("添加中控信息");
		if(centralEntity==null){
			bean.put("code", 1);
			bean.put("message", "中控信息丢失");
		}
		if(centralTopicMapper.findCentralByMac(centralEntity.getMac())==null){
		centralEntity.setId(UUIDUtil.generate());
		centralEntity.setIsEnable(true);
		centralEntity.setUpdateTime(new Date());
		centralEntity.setCreateTime(new Date());
		centralTopicMapper.insertModel(centralEntity);
		bean.put("cmd", centralEntity.getCmd());
		bean.put("isSub", centralEntity.getIsSub());
		bean.put("channel", centralEntity.getChannel());
		bean.put("mac", centralEntity.getMac());
		bean.put("name", centralEntity.getName());
		bean.put("type", centralEntity.getType());
		bean.put("version", centralEntity.getVersion());
		bean.put("signLight", centralEntity.getSignLight());
		return bean;
		}
		bean.put("code", 0);
		bean.put("message", "success");
		return bean;
	}

	public HashMap<String, Object> findCentralVersion(
			String mac) throws Exception {
		HashMap<String, Object> bean  =new HashMap<String, Object>();
		log.info("获取中控版本信息");
		CentralEntity centralEntity=centralTopicMapper.findCentralByMac(mac);
		bean.put("version", centralEntity.getVersion());
		return bean;
	}
}
